<?php
/**
 * Created by litong on Date: 2019/2/24 0024 下午 8:49
 *
 */
$host="localhost";$username="root";$password="";$dbname="php_study";
$sql = "CREATE TABLE my_guests(id INT(6) AUTO_INCREMENT PRIMARY KEY,firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,email VARCHAR(50),reg_date TIMESTAMP);";
try{
  $connection = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  $connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  $connection->exec($sql);
  echo "sql语句执行成功";
}catch(PDOException $e){
  echo $e->getMessage();
}